package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.wechat.domain.CampFacility;
import com.ruoyi.wechat.domain.WxCampFacility;
import com.ruoyi.wechat.service.ICampFacilityService;
import com.ruoyi.wechat.service.IWxCampFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营地服务设施记录表Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/wechatt/campfacility")
public class WxCampFacilityController extends BaseController {
    @Autowired
    private ICampFacilityService campFacilityService;

    /**
     * 查询营地服务设施记录表列表
     */

    @GetMapping("/list")
    public TableDataInfo list(CampFacility campFacility)
    {
        startPage();
        List<CampFacility> list = campFacilityService.selectCampFacilityList(campFacility);
        return getDataTable(list);
    }


    /**
     * 获取营地服务设施记录表详细信息
     */

    @GetMapping(value = "/{cfId}")
    public AjaxResult getInfo(@PathVariable("cfId") String cfId)
    {
        return success(campFacilityService.selectCampFacilityByCfId(cfId));
    }
    /**
     * 获取id
     */
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfoo(@PathVariable String id)
    {
        return success(campFacilityService.selectCampFacilityByCampId(id));
    }
    /**
     * 新增营地服务设施记录表
     */

    @Log(title = "营地服务设施记录表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacility wxcampFacility)
    {
        if(wxcampFacility.getCampId()==null){
            return error("营地Id不能为空");
        }
        if(wxcampFacility.getFacilityIds()==null){
            return error("服务设施Id不能为空");
        }
        return toAjax(campFacilityService.insertCampFacility(wxcampFacility.getCampId(), wxcampFacility.getFacilityIds()));
    }

    /**
     * 修改营地服务设施记录表
     */

    @Log(title = "营地服务设施记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampFacility campFacility)
    {
        return toAjax(campFacilityService.updateCampFacility(campFacility));
    }

    /**
     * 删除营地服务设施记录表
     */

    @Log(title = "营地服务设施记录表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cfIds}")
    public AjaxResult remove(@PathVariable String[] cfIds)
    {
        return toAjax(campFacilityService.deleteCampFacilityByCfIds(cfIds));
    }

}
